﻿using MediatR;
using T_vehicle.API.Application.Command.TiresUsedCommand;
using T_vehicle.Infrastructure.Impl;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.TiresUsedCommandHandlers
{
    public class PDelTiresUsedCommandHandlers:IRequestHandler<PDelTiresUsedCommand,int>
    {
        private readonly ITiresUsedRepository tiresUsedRepository;

        public PDelTiresUsedCommandHandlers(ITiresUsedRepository tiresUsedRepository)
        {
            this.tiresUsedRepository = tiresUsedRepository;
        }

        public async Task<int> Handle(PDelTiresUsedCommand request, CancellationToken cancellationToken)
        {
            var Id =  request.TiresUsedId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await tiresUsedRepository.GetAsync(x => Id.Contains(x.TiresUsedId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await tiresUsedRepository.UpdateAsyncRange(list);
        }
    }
}
